<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="description" content="">
		<meta name="author" content="">
		<title>核销</title>
		<link rel="stylesheet" href="../../css/base.css" />
		<link rel="stylesheet" href="../../css/common.css" />
		<!-- Bootstrap Core CSS -->
		<link href="../../sbadmin/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
		<!-- MetisMenu CSS -->
		<link href="../../sbadmin/bower_components/metisMenu/dist/metisMenu.min.css" rel="stylesheet">
		<!-- DataTables CSS -->
		<link href="../../sbadmin/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet">
		<!-- Custom CSS -->
		<link href="../../sbadmin/dist/css/sb-admin-2.css" rel="stylesheet">
		<!-- Custom Fonts -->
		<link href="../../sbadmin/bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
		<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
		<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
		<!--[if lt IE 9]>
	<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
	<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
		<style>
			body {
				padding: 0 15px !important;
			}
			
			.wo-form-itemcc {
				width: 200px;
			}
			
			#dataTables-example_length {
				position: absolute;
				top: -35px;
				left: 30px;
				z-index: 1000;
			}
		</style>
	</head>

	<body style="background:#FFF;">
		<div class="comm-tt-font">进店核销</div>
		<div class="mt20 clb">
			<div class="um-tbox fl">
				<input type="text" class="um-input" id="uname" placeholder="请输入手机号" />
			</div>
			<a href="javascript:void(0);" class="fl wo-qbtn" id="woQd">确定</a>
		</div>

		<div class="wop-ccbox none" id="woPmsg">
			<div class="wop-name" id="wopName"></div>
			<div class="wo-form-item clb">
				<div class="fl">
					<div class="wo-form-itemtt fl">会员编号：</div>
					<div class="wo-form-itemcc fl" id="vipNum"></div>
				</div>
				<div class="fl">
					<div class="wo-form-itemtt fl">手机号：</div>
					<div class="wo-form-itemcc fl" id="woTel"></div>
				</div>
			</div>
			<div class="wo-form-item clb">
				<div class="fl">
					<div class="wo-form-itemtt fl">身份证：</div>
					<div class="wo-form-itemcc fl" id="idCard"></div>
				</div>
				<div class="fl">
					<div class="wo-form-itemtt fl">电子邮件：</div>
					<div class="wo-form-itemcc fl" id="mail"></div>
				</div>
			</div>
			<div class="wo-form-item clb">
				<div class="fl">
					<div class="wo-form-itemtt fl">生日：</div>
					<div class="wo-form-itemcc fl" id="birth"></div>
				</div>
				<div class="fl">
					<div class="wo-form-itemtt fl">通讯地址：</div>
					<div class="wo-form-itemcc fl" id="addr"></div>
				</div>
			</div>
			<div class="wo-form-item clb">
				<div class="fl">
					<div class="wo-form-itemtt fl">性别：</div>
					<div class="wo-form-itemcc fl" id="sex"></div>
				</div>
				<div class="fl">
					<div class="wo-form-itemtt fl">注册日期：</div>
					<div class="wo-form-itemcc fl" id="time"></div>
				</div>
			</div>
		</div>

		<div class="bars-box none pr" id="woBox" style="width: 100%;overflow-x: scroll;">
			<div style="width: 100%;height: 50px;position: relative;">
				<a data-type="xls" class="expbtn fr mt10 mr10" id="export" href="javascript:;">导出列表</a>
			</div>
			<div class="panel-body" style="padding-top: 0 !important;width: 2100px;">
				<div class="dataTable_wrapper" id="app">
					<table class="table table-striped table-bordered table-hover" id="dataTables-example">
						<thead>
							<tr>
								<th>订单号</th>
								<th>第三方流水号</th>
								<th>商品名</th>
								<th>商品分类</th>
								<th>销售类型</th>
								<th>销售门店</th>
								<th>应收金额</th>
								<th>实付金额</th>
								<th>支付方式</th>
								<th>销售方式</th>
								<th>支付状态</th>
								<th>支付交易时间</th>
								<th>截至有效期</th>
								<th>订单状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody id="list-td">

						</tbody>
					</table>
				</div>
				<!-- /.table-responsive -->
			</div>
			<div class="no-tit">
				<img class="no-pic" src="../../img/error.jpg" />
				<p class="no-txt">没有符合筛选条件的记录</p>
			</div>
		</div>
		<div class="comm-mbbox none"></div>
		<div class="hx-showbox none">
			<div class="hx-sgtbox">即将扣除一次拍摄次数！</div>
			<div style="margin: 10px 0 0 55px;">
				<select class="item-select" id="perName"></select>
			</div>
			<div>
				<textarea class="hx-textarea" id="remark" placeholder="填写备注信息："></textarea>
			</div>
			<div class="clb mt10" style="margin-left: 155px;">
				<a href="javascript:void(0);" class="fl qx-btn" id="hx-closebtn" style="width: 80px;">取消</a>
				<a href="javascript:void(0);" class="fl qr-btn ml20" id="hxCfmBtn" style="width: 80px;">确定</a>
			</div>
		</div>
		<!-- jQuery -->
		<script src="../../sbadmin/bower_components/jquery/dist/jquery.min.js"></script>
		<!-- Bootstrap Core JavaScript -->
		<script src="../../sbadmin/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<!-- Metis Menu Plugin JavaScript -->
		<script src="../../sbadmin/bower_components/metisMenu/dist/metisMenu.min.js"></script>
		<!-- DataTables JavaScript -->
		<script src="../../sbadmin/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
		<script src="../../sbadmin/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
		<!-- Custom Theme JavaScript -->
		<script src="../../sbadmin/dist/js/sb-admin-2.js"></script>
		<script src="../../js/layer/layer.js"></script>
		<script src="../../js/common.js"></script>
		<script type="text/javascript" src="../../js/jquery-ui.min.js"></script>
		<script type="text/javascript" src="../../js/Blob.js"></script>
		<script type="text/javascript" src="../../js/FileSaver.js"></script>
		<script type="text/javascript" src="../../js/tableExport.js"></script>
		<script type="text/javascript" src="../../js/jquery-ui.min.js"></script>
		<!-- Page-Level Demo Scripts - Tables - Use for reference -->
	</body>

	<script>
		$(".hx-showbox").draggable(); //为模态对话框添加拖拽
		$("#woQd").click(function() {
			if($("#uname").val() == "") {
				layar("请输入手机号");
			} else {
				$("#wopName").html("");
				$("#vipNum").html("");
				$("#woTel").html("");
				$("#idCard").html("");
				$("#mail").html("");
				$("#birth").html("");
				$("#addr").html("");
				$("#sex").html("");
				$("#time").html("");
				var unameText = $("#uname").val();;
				getList(unameText);
				getOrderList(unameText);
			}

		})

		function getList(tel) {
			var user = {
				phone: tel,
				type: 0
			}
			$.ajax({
				url: "https://order.wz1996.wang/wzbg/user/query/customer",
				type: 'post',
				contentType: 'application/json',
				data: JSON.stringify(user),
				beforeSend: function(request) {
					request.setRequestHeader("token", localStorage.getItem("token"));
				},
				success: function(data) {
					console.log(data);
					$("#woPmsg").show();
					$("#woBox").show();
					if(data.code == "1") {
						$("#wopName").html(data.data[0].name);
						$("#vipNum").html(data.data[0].id);
						$("#woTel").html(data.data[0].phone);
						$("#idCard").html(data.data[0].identityCard);
						$("#mail").html(data.data[0].email);
						$("#birth").html(data.data[0].birthday.split(" ")[0]);
						$("#addr").html(data.data[0].address);
						if(data.data[0].sex == "1") {
							$("#sex").html("男");
						} else if(data.data[0].sex == "0") {
							$("#sex").html("女");
						}
						$("#time").html(data.data[0].createTime.split(" ")[0]);
					} else if(data.code == "-1") {
						layar(data.msg);
						setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
					} else {
						layar(data.msg);
					}

				},
				error: function(e) {
					errcode(e);
				}
			});
		}

		function getOrderList(phone) {
			$("#dataTables-example").dataTable().fnDestroy();
			var post_data = {
				"orderDetail": {
					"receiverPhone": phone
				}
			}
			$.ajax({
				url: "https://order.wz1996.wang/wzbg/order/query",
				type: 'post',
				contentType: 'application/json',
				data: JSON.stringify(post_data),
				beforeSend: function(request) {
					request.setRequestHeader("token", localStorage.getItem("token"));
				},
				success: function(data) {
					console.log(data);
					if(data.code == "1") {
						var html = "";
						for(var i = 0; i < data.data.length; i++) {
							html += "<tr class='odd gradeX'>";
							html += "<td>" + data.data[i].outTradeNo + "</td>";
							html += "<td>" + data.data[i].batch + "</td>";
							html += "<td>" + data.data[i].skuName + "</td>";
							if(data.data[i].skuCategory == 2) {
								html += "<td>儿童</td>";
							} else if(data.data[i].skuCategory == 3) {
								html += "<td>亲子</td>";
							} else if(data.data[i].skuCategory == 4) {
								html += "<td>孕妇</td>";
							} else if(data.data[i].skuCategory == 5) {
								html += "<td>全家福（三代）</td>";
							}
							html += "<td>" + data.data[i].saleType + "</td>";
							if(data.data[i].storeName == "" || data.data[i].storeName == null || data.data[i].storeName == undefined) {
								html += "<td>--</td>";
							} else {
								html += "<td>" + data.data[i].storeName + "</td>";
							}
							html += "<td>" + data.data[i].price + "</td>";
							html += "<td>" + data.data[i].actualPayedPrice + "</td>";
							html += "<td>" + data.data[i].payType + "</td>";
							if(data.data[i].isOnline == "1") {
								html += "<td>线上</td>";
							} else {
								html += "<td>线下</td>";
							}
							if(data.data[i].status == "1" || data.data[i].status == "3") {
								html += "<td>已支付</td>";
							} else {
								html += "<td>--</td>";
							}
							html += "<td>" + data.data[i].createTime + "</td>";
							html += "<td>" + data.data[i].expired + "</td>";
							var expired = data.data[i].expired;
							var myDate = new Date(); //获取系统当前时间
							var mytime = myDate.toLocaleString(); //获取当前时间
							var oDate1 = new Date(expired);
							var oDate2 = new Date(mytime);
							if(data.data[i].status == "3") {
								html += "<td>停止</td>";
							} else if(data.data[i].status == "1") {
								html += "<td>有效</td>";
							} else if(oDate1.getTime() < oDate2.getTime()) {
								html += "<td>过期</td>";
							}
							if(data.data[i].status == "1") {
								html += "<td><a href='javascript:void(0)' id='" + data.data[i].id + "' class='woH'>核销</a></td>";
							} else {
								html += "<td><a href='javascript:void(0)' class='woH'>--</a></td>";
							}
							html += "</tr>";
						}
						$("#list-td").html(html);
						$('#dataTables-example').DataTable({
							responsive: false,
							bLengthChange: true,
							aLengthMenu: [
								[10, 25, 50, 100, -1],
								[10, 25, 50, 100, "所有"]
							], // 定义每页显示数据数量
							bSort: true,
							paging: true,
							bFilter: true,
							searching: false,
							bInfo: true,
							bAutoWidth: true,
							"oLanguage": {
								"sLengthMenu": "每页显示 _MENU_ 条记录",
								"sZeroRecords": "抱歉， 没有找到",
								"sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
								"sInfoEmpty": "没有数据",
								"sInfoFiltered": "(从 _MAX_ 条数据中检索)",
								"oPaginate": {
									"sFirst": "首页",
									"sPrevious": "前一页",
									"sNext": "后一页",
									"sLast": "尾页"
								},
								"sSearch": "查询条件:",
								"sZeroRecords": "没有检索到数据",
								"sProcessing": "<img src='./loading.gif' />"
							}
						});
					} else if(data.code == "-1") {
						layar(data.msg);
						setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
					} else {
						layar(data.msg);
					}

				},
				error: function(e) {
					errcode(e);
				}
			});

		}
		$(".comm-mbbox").css("width", $(window).width() + 250);

		$("#dataTables-example").on("click", ".hx-btn", function() {
			$(".comm-mbbox").show();
			$(".hx-showbox").show();
		})
		$("#hx-closebtn").click(function() {
			$(".comm-mbbox").hide();
			$(".hx-showbox").hide();
		})
		//核销门店
		//核销
		var hxId = "";
		$("#list-td").on("click", ".woH", function() {
			getStores();
			$(".comm-mbbox").show();
			$(".hx-showbox").show();
			hxId = $(this).attr("id");
		})

		$("#hxCfmBtn").click(function() {
			var remark = $("#remark").val()
			var storeId = $("#perName option:selected").val();
			console.log(storeId);
			if(storeId == "" || storeId == null || storeId == undefined) {
				layar("请选择门店！");
			} else {
				var post_data = {
					"orderDetailId": hxId,
					"remark": remark,
					"storeId": storeId
				}
				$.ajax({
					url: "https://order.wz1996.wang/wzbg/checkrecord/check/",
					type: 'post',
					contentType: 'application/json',
					data: JSON.stringify(post_data),
					beforeSend: function(request) {
						request.setRequestHeader("token", localStorage.getItem("token"));
					},
					success: function(data) {
						console.log(data)
						if(data.code == "1") {
							layar("核销成功！");
							setTimeout(function() {
								$(".comm-mbbox").hide();
								$(".hx-showbox").hide();
							}, 2000);

						} else if(data.code == "-1") {
							layar(data.msg);
							setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
						} else {
							layar(data.msg);
							setTimeout(function() {
								$(".comm-mbbox").hide();
								$(".hx-showbox").hide();
							}, 2000);
						}
					},
					error: function(e) {
						errcode(e);
					}
				});
			}

		})

		function getStores() {
			$.ajax({
				url: "https://order.wz1996.wang/wzbg/store/user/stores",
				type: 'get',
				contentType: 'application/json',
				beforeSend: function(request) {
					request.setRequestHeader("token", localStorage.getItem("token"));
				},
				success: function(data) {
					console.log(data);
					var html = "";
					if(data.code == "1") {
						html += "<option value=''>--请选择--</option>"
						for(var i = 0; i < data.data.length; i++) {
							html += "<option id=" + data.data[i].id + " value=" + data.data[i].id + ">" + data.data[i].name + "</option>"
						}
						$("#perName").html(html);
					} else if(data.code == "-1") {
						layar(data.msg);
						setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
					} else {
						layar(data.msg);
					}
				},
				error: function(e) {
					errcode(e);
				}
			});
		}
	</script>

</html>